package bigdata;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.PartitionService;
import com.hazelcast.instance.GroupProperty;
import com.hazelcast.monitor.LocalMapStats;

public class SlaveMember {
	private final static Logger logger = LoggerFactory.getLogger(SlaveMember.class);

	public static void main(String[] args) throws InterruptedException {
		HazelcastInstance hz = Hazelcast.newHazelcastInstance(PrimeMember.config());

		IMap<Integer, Rule> ruleMap = hz.getMap("ruleMap");
		PartitionService partitionService = hz.getPartitionService();
		while (true) {
			LocalMapStats mapStatistics = ruleMap.getLocalMapStats();
			logger.info(
					"isClusterSafe:{},isLocalMemberSafe:{},rulemap.size:{},backpressure.enabled:{}, \n number of entries owned on this node = {}",
					partitionService.isClusterSafe(), partitionService.isLocalMemberSafe(), ruleMap.size(),
					hz.getConfig().getProperty(GroupProperty.BACKPRESSURE_ENABLED), mapStatistics.getOwnedEntryCount());
			Thread.sleep(1000);
		}
	}
}
